-----------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  /Users/juanpablouribetrujillo/My Drive (jp.uribe86@gmail.com)/Research/MyPapers/MTU/JUE/analys
> is/sample_composition.log
  log type:  text
 opened on:  24 Jun 2024, 22:23:15

. *----------------------------------------------------------------------------------;
. *-------------------------****** OUTPUT SETTINGS *****---------------------;
. *----------------------------------------------------------------------------------;
. *settings some settings that are common for the set of plots on this dofile;
.  local pdf_plot_settings =      `"scale(*1.5) ymtick(##4) "';

. **EXTRA LINES: \hline\hline \bigskip\\[6ex]) ;
.  *settings for latex tables ;
.                                                 global prehead_start "prehead(\begin{table}[!htb]\centeri
> ng 
>                 \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}  
>                 \caption{@title}
>                 \setlength{\tabcolsep}{1pt}";

.                                 global prehead_start_longcol "prehead(\begin{table}[!htb]\centering 
>                 \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}  
>                 \caption{@title}
>                 \setlength{\tabcolsep}{7pt}";

.                 local font_size "";

.                                 global prehead_end         "\begin{tabular}{l*{@span}{c}}\hline\hline)";

.                                 global prehead_end_bigskip "\begin{tabular}{l*{@span}{c}}\hline\hline \bi
> gskip\\[6ex])";

.                                 global postfoot "postfoot(\hline\hline
>                 \multicolumn{@span}{m{0.9\textwidth}}{ \footnotesize @note. @starlegend. }
>                 \end{tabular}\end{table})";

.                                                                                                         l
> ocal tex_settigns  = `"
>                 ${prehead_start}
>                 `font_size'
>                 ${prehead_end}
>                 ${postfoot}
>                 "';

.         *xlabel(1980(5)2010);
. *ymtick(-0.2(0.2)0.6) ;
.  *ylabel(-0.2(0.2)0.6);
. *ysc(r(-0.2 0.6));
. *xmtick(1984(1)2008) ;
.  *----------------------------------------------------------------------------------;
. *----------------------------------------------------------------------------------;
. **************************************;
. use "../data/hpms_hwy_stats_88_08.dta", clear  ;

. do "_setup_expenditure.do";

. /******************************************************************
> 
> setup_expenditure.do
> 
> Subroutine to calculate expenditure variables for all analysis programs;
> 
> mt 20190506
> *******************************************************************/
. # delim ;  
delimiter now ;
. * expenditure on length and IRI from SF12a. Check that categories are right. Can we break apart ROW?;
. *conversion factor to get to 10^6 2010 dollars;
. gen deflate= 1/(ppiaco_2010*10);

. *gen deflate= 1;
. *consolidate rural and urban SF12a variables that we need;
. local rur_urb_list      "exp_eng_row_IH                 exp_row_IH              exp_eng_IH              e
> xp_new_cons_IH
>                         exp_relocation_IH               exp_recons_IH           exp_recons_add_IH       e
> xp_recons_noadd_IH
>                         exp_maj_wide_IH                 exp_R3_IH               exp_R3_min_wide_IH      e
> xp_R3_rehab_rest_IH    
>                         exp_R3_resurf_IH
>                         exp_new_bridge_IH exp_bridgereplacement_IH exp_majorbridgerehab_IH exp_minorbridg
> erehab_IH exp_bridge_IH
>                         ";

. foreach exp_var of local rur_urb_list{;
  2.                 replace `exp_var'_urban=cond(`exp_var'_urban==.,0,`exp_var'_urban);
  3.                 replace `exp_var'_rural=cond(`exp_var'_rural==.,0,`exp_var'_rural);
  4.                 gen `exp_var'_all = `exp_var'_urban + `exp_var'_rural;
  5.                 drop `exp_var'_urban `exp_var'_rural;
  6.                 };
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)

. *consolidate SF12a variables into nominal construction and resurfacing for pre and post 1998;
. *NB: exp_new_cons_IH_all and exp_maj_wide_IH_all are common to pre and post 1998 construction;
. gen exp_L_IH_SF12a_n_old=       exp_eng_row_IH_all + exp_new_cons_IH_all + exp_maj_wide_IH_all;

. gen exp_IRI_IH_SF12a_n_old=     exp_recons_IH_all  + exp_R3_IH_all;

.  gen exp_L_IH_SF12a_n_new=      exp_row_IH_all     + exp_eng_IH_all      + exp_new_cons_IH_all  + exp_rel
> ocation_IH_all + exp_maj_wide_IH_all;

.                         gen exp_IRI_IH_SF12a_n_new=     exp_recons_add_IH  + exp_recons_noadd_IH + exp_R3
> _min_wide_IH   + exp_R3_rehab_rest_IH  + exp_R3_resurf_IH;

. * Do the same for bridge expenditure ;
. gen exp_bridge_IH_SF12a_n_new=cond( year>1998,
>                                                                         exp_new_bridge_IH_all+exp_bridger
> eplacement_IH_all+exp_majorbridgerehab_IH_all+exp_minorbridgerehab_IH_all,.);
(147,240 missing values generated)

.                                                                         gen exp_bridge_IH_SF12a_n_old=con
> d( year<=1998,
>                                                                         exp_bridge_IH_all,.);
(160,858 missing values generated)

. *diagnostics -- should all be zero -- this test won't work for construction;
. sum exp_IRI_IH_SF12a_n_new exp_IRI_IH_SF12a_n_old if year>1998;

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
exp_IRI_IH~w |    160,858    220065.6      226117          0    1142287
exp_IRI_IH~d |    160,858           0           0          0          0

. sum exp_IRI_IH_SF12a_n_new exp_IRI_IH_SF12a_n_old if year<=1998;

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
exp_IRI_IH~w |    147,240           0           0          0          0
exp_IRI_IH~d |    147,240      107408      108656          0     560136

. *consolidate pre and post 1998 variable construction;
. gen exp_IRI_IH_SF12a_n =        cond(year>1998, exp_IRI_IH_SF12a_n_new, exp_IRI_IH_SF12a_n_old);

. gen exp_L_IH_SF12a_n =          cond(year>1998, exp_L_IH_SF12a_n_new, exp_L_IH_SF12a_n_old);

. gen exp_bridge_IH_SF12a_n =             cond(year>1998, exp_bridge_IH_SF12a_n_new, exp_bridge_IH_SF12a_n_
> old);

. *clean up -- save reloacation;
. gen temp = exp_relocation_IH_all;

. gen temp2 =exp_row_IH_all ;

. foreach exp_var of local rur_urb_list{;
  2.                 drop `exp_var'_all;
  3.                 };

.                 drop *_new *_old;

. rename temp exp_relocation_IH_all_n;

.  rename temp2 exp_row_IH_all_n ;

. *calculate total IH and SF12a maintenance;
. gen exp_IH_total_SF12_n = exp_IH_mtn_all + exp_IH_k_all;
(351 missing values generated)

. gen exp_IH_mtn_SF12a_n = exp_IH_total_SF12_n - exp_IRI_IH_SF12a_n - exp_L_IH_SF12a_n -exp_bridge_IH_SF12a
> _n;
(351 missing values generated)

. sum exp_IH_mtn_SF12a_n, d ;

                     exp_IH_mtn_SF12a_n
-------------------------------------------------------------
      Percentiles      Smallest
 1%       -73065        -796329
 5%         4228        -796329
10%     7764.049        -796329       Obs             307,747
25%        19215        -796329       Sum of wgt.     307,747

50%        48833                      Mean           75766.26
                        Largest       Std. dev.      104646.2
75%     100944.5        2017193
90%     181282.9        2062267       Variance       1.10e+10
95%     237426.6        3278198       Skewness       2.799105
99%       458010        3303381       Kurtosis       40.18784

. replace exp_IH_mtn_SF12a_n= cond(exp_IH_mtn_SF12a_n<0,0,exp_IH_mtn_SF12a_n );
(5,948 real changes made)

. sum exp_IH_mtn_SF12a_n, d ;

                     exp_IH_mtn_SF12a_n
-------------------------------------------------------------
      Percentiles      Smallest
 1%            0              0
 5%         4228              0
10%     7764.049              0       Obs             307,747
25%        19215              0       Sum of wgt.     307,747

50%        48833                      Mean            78426.6
                        Largest       Std. dev.      97296.26
75%     100944.5        2017193
90%     181282.9        2062267       Variance       9.47e+09
95%     237426.6        3278198       Skewness       4.440624
99%       458010        3303381       Kurtosis       45.17407

. ;
. *convert to real 2010 USD 10^6;
. *NB: deflate calculated in calling program;
. rename app_IH app_IH_n;

. rename exp_IH_mtn_all exp_IH_mtn_SF12_n;

. ren rev_grand_total_mt rev_grand_total_mt_n;

. ren rev_total_h rev_total_h_n;

. ren rev_total_mt rev_total_mt_n ;

. ren rev_total_m_fuel_h rev_total_m_fuel_h_n ;

. local real_list "exp_IH_total_SF12 exp_IH_mtn_SF12a exp_IRI_IH_SF12a exp_L_IH_SF12a app_IH exp_IH_mtn_SF1
> 2 exp_relocation_IH_all 
>                                  rev_grand_total_mt rev_total_h rev_total_mt rev_total_m_fuel_h
>                                  exp_bridge_IH_SF12a exp_row_IH_all
>                                  ";

. foreach exp_var of local real_list{;
  2.                 gen `exp_var'_r=deflate*`exp_var'_n;
  3.                 drop `exp_var'_n;
  4.                 };
(351 missing values generated)
(351 missing values generated)
(77,386 missing values generated)
(351 missing values generated)
(105,706 missing values generated)
(399 missing values generated)
(105,706 missing values generated)
(399 missing values generated)

.         forvalues i=1(1)5{;
  2.                                 gen deflate_L`i'= 1/(ppiaco_2010_L`i'*10);
  3.                 ren L`i'FHWA_apport_LW L`i'FHWA_apport_LW_n;
  4.                 gen L`i'FHWA_apport_LW_r=deflate_L`i'*L`i'FHWA_apport_LW_n;
  5.                 drop L`i'FHWA_apport_LW_n;
  6. };
(303 missing values generated)
(351 missing values generated)
(399 missing values generated)
(447 missing values generated)
(495 missing values generated)

.                                                 *label and drop superflous expenditure data;
. label var       exp_IH_total_SF12_r     "Total IH exp SF12 real";

. label var       exp_IH_mtn_SF12_r       "Total IH maint exp SF12 real";

. label var       exp_IH_mtn_SF12a_r      "Total IH maint exp SF12a real";

.  label var      exp_IRI_IH_SF12a_r      "Total IH IRI exp SF12a real";

.  label var      exp_L_IH_SF12a_r        "Total IH L exp SF12a real";

. label var       app_IH_r                "Total IH approp real";

. label var       exp_relocation_IH_all   "Total IH exp relocation, >1998";

. label var   rev_grand_total_mt_r          "Total revenue mass transit account real [source: FE9 p2 ]";

. label var   rev_total_mt_r        "Total revenue highway and mass transit account real [source: FE9 p2 ]"
> ;

. label var   rev_total_h  "Total revenue highway account real [source: FE9 p2 ]";

. label var rev_total_m_fuel_h                     "Total Revenue motor fuel  (Highway motor fuel) [source:
>  FE9 p1 ]";

.         *drop exp_IH_k_rural-exp_subtotal_mtn_urban;
. exit;

end of do-file

. do "_cleaning_and_new_variables_sample.do";

. # d ;
delimiter now ;
. *label variables to mathc the names in the tables ;
. label var exp_L_IH_SF12a_r "\( Y^L \)";

. label var  exp_IRI_IH_SF12a_r "\( Y^L\:in\:IRI \)";

. label var  exp_IH_mtn_SF12a_r "\( Y^L\: in\: Maint.\)";

. ****************************************************;
. *calculate differences in miles and IRI;
. *local D_vars "u_iri_IH u_iri_urban u_iri_rural u_lane_miles_IH u_lane_miles_rural u_lane_miles_urban";
. local D_vars iri ;

. sort state id year ;

. foreach varname of local D_vars{;
  2.         *changed from leads to lags, 20190429;
.         gen D`varname'=cond(
>                         id[_n]==id[_n-1]&
>                         state[_n]==state[_n-1]&
>                         `varname'[_n]!=.&`varname'[_n-1]!=.&
>                         `varname'[_n]!=0&`varname'[_n-1]!=0&
>                         year[_n]==year[_n-1]+1,
>                         `varname'[_n]-`varname'[_n-1],.);
  3.         gen lag_`varname'=cond(
>                         id[_n]==id[_n-1]&
>                         state[_n]==state[_n-1]&
>                         `varname'[_n]!=.&`varname'[_n-1]!=.&
>                         `varname'[_n]!=0&`varname'[_n-1]!=0&
>                         year[_n]==year[_n-1]+1,
>                         `varname'[_n-1],.);
  4.                                         };
(44,521 missing values generated)
(44,521 missing values generated)

. sum Diri d_iri;

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
        Diri |    263,577   -1.215084    28.56901       -554        592
       d_iri |    263,577   -1.215084    28.56901       -554        592

.         drop d_iri;

. ** indicator for states with maintenance reported in HPMS;
. *bysort state year : egen D_exp_I2=max(I2_t) if I2_t!=.;
.  *label var D_exp_I2 "Dummy=1 for state year if if at least one sample id reports maintenance";
.         *keep if _n<50;
. *Total lane miles IH in each state-year;
.  bysort state year : egen lane_miles_st=total(lane_miles);

. label var  lane_miles_st "Total IH lane miles in state year (HPMS-sample)" ;

. *Total lane miles resurfaced IH in each state-year;
.  gen lane_miles_x=I2_t*lane_miles;
(673 missing values generated)

. bysort state year : egen lane_milesI2_st=total(lane_miles_x);

. drop lane_miles_x;

. label var  lane_milesI2_st "Total I2 IH lane miles in state year (HPMS-sample)" ;

. *keep year state lane_miles lane_miles_st lane_milesI2_st I2_t;
. *order year state lane_miles lane_miles_st lane_milesI2_st I2_t;
. * Real IH Expenditure per IH lane mile;
. gen app_IH_plm=                 (app_IH_r/lane_miles_st );
(77,531 missing values generated)

. gen exp_IRI_IH_SF12a_plm=       (exp_IRI_IH_SF12a_r/lane_miles_st );
(673 missing values generated)

. gen exp_L_IH_SF12a_plm=         (exp_L_IH_SF12a_r/lane_miles_st );
(673 missing values generated)

. label var app_IH_plm            "Appropriations per lane mile" ;

. label var exp_IRI_IH_SF12a_plm  "Exp. Resurfacing per lane mile" ;

. label var exp_L_IH_SF12a_plm    "Exp. construction per lane mile" ;

. * Real IH Expenditure per resurfaced IH lane mile;
. gen app_IH_I2_plm=                      (app_IH_r/lane_milesI2_st );
(126,970 missing values generated)

. gen exp_IRI_IH_I2_SF12a_plm=            (exp_IRI_IH_SF12a_r/lane_milesI2_st );
(59,249 missing values generated)

. gen exp_L_IH_I2_SF12a_plm=              (exp_L_IH_SF12a_r/lane_milesI2_st );
(59,249 missing values generated)

. label var app_IH_I2_plm                 "Appropriations per resurf.lane m." ;

. label var exp_IRI_IH_I2_SF12a_plm       "Exp. Resurfacing per resurf. lane m." ;

. label var exp_L_IH_I2_SF12a_plm         "Exp. Construction per resurf.lane m." ;

. forvalues i=1(1)5{;
  2.                                 gen L`i'FHWA_apport_LW_r_plm=                   (L`i'FHWA_apport_LW_r/
> lane_milesI2_st );
  3. };
(59,279 missing values generated)
(59,279 missing values generated)
(59,279 missing values generated)
(59,279 missing values generated)
(59,279 missing values generated)

.         tab state year if Diri==.;

                     |                             Book year
     State fips code |      1980       1981       1982       1983       1984       1985 |     Total
---------------------+------------------------------------------------------------------+----------
             ALABAMA |         1          1          1          1          1          1 |       439 
             ARIZONA |         1          1          1          1          1          1 |     1,064 
            ARKANSAS |         1          1          1          1          1          1 |       641 
          CALIFORNIA |         1          1          1          1          1          1 |     1,437 
            COLORADO |         1          1          1          1          1          1 |       492 
         CONNECTICUT |         1          1          1          1          1          1 |     1,397 
            DELAWARE |         1          1          1          1          1          1 |       111 
DISTRICT OF COLUMBIA |         0          0          0          0          0          0 |        78 
             FLORIDA |         1          1          1          1          1          1 |     1,548 
             GEORGIA |         1          1          1          1          1          1 |     1,267 
               IDAHO |         1          1          1          1          1          1 |       492 
            ILLINOIS |         1          1          1          1          1          1 |       846 
             INDIANA |         1          1          1          1          1          1 |       683 
                IOWA |         1          1          1          1          1          1 |     2,175 
              KANSAS |         1          1          1          1          1          1 |       769 
            KENTUCKY |         1          1          1          1          1          1 |       767 
           LOUISIANA |         1          1          1          1          1          1 |     1,301 
               MAINE |         1          1          1          1          1          1 |     1,256 
            MARYLAND |         1          1          1          1          1          1 |       674 
       MASSACHUSETTS |         1          1          1          1          1          1 |     1,370 
            MICHIGAN |         1          1          1          1          1          1 |     1,280 
           MINNESOTA |         1          1          1          1          1          1 |       289 
         MISSISSIPPI |         1          1          1          1          1          1 |       497 
            MISSOURI |         1          1          1          1          1          1 |       537 
             MONTANA |         1          1          1          1          1          1 |       308 
            NEBRASKA |         1          1          1          1          1          1 |       243 
              NEVADA |         1          1          1          1          1          1 |       701 
       NEW HAMPSHIRE |         1          1          1          1          1          1 |       489 
          NEW JERSEY |         1          1          1          1          1          1 |       704 
          NEW MEXICO |         1          1          1          1          1          1 |       537 
            NEW YORK |         1          1          1          1          1          1 |       760 
      NORTH CAROLINA |         1          1          1          1          1          1 |       840 
        NORTH DAKOTA |         1          1          1          1          1          1 |       252 
                OHIO |         1          1          1          1          1          1 |     1,407 
            OKLAHOMA |         1          1          1          1          1          1 |     1,762 
              OREGON |         1          1          1          1          1          1 |       940 
        PENNSYLVANIA |         1          1          1          1          1          1 |     4,911 
        RHODE ISLAND |         1          1          1          1          1          1 |       278 
      SOUTH CAROLINA |         1          1          1          1          1          1 |       431 
        SOUTH DAKOTA |         1          1          1          1          1          1 |       528 
           TENNESSEE |         1          1          1          1          1          1 |     1,274 
               TEXAS |         1          1          1          1          1          1 |     1,487 
                UTAH |         1          1          1          1          1          1 |     1,019 
             VERMONT |         1          1          1          1          1          1 |       188 
            VIRGINIA |         1          1          1          1          1          1 |     1,073 
          WASHINGTON |         1          1          1          1          1          1 |       426 
       WEST VIRGINIA |         1          1          1          1          1          1 |     1,234 
           WISCONSIN |         1          1          1          1          1          1 |       930 
             WYOMING |         1          1          1          1          1          1 |       389 
---------------------+------------------------------------------------------------------+----------
               Total |        48         48         48         48         48         48 |    44,521 


                     |                             Book year
     State fips code |      1986       1987       1988       1989       1990       1991 |     Total
---------------------+------------------------------------------------------------------+----------
             ALABAMA |         1          1        145        145          1          2 |       439 
             ARIZONA |         1          1        174        177          0          1 |     1,064 
            ARKANSAS |         1          1        123        123         67         62 |       641 
          CALIFORNIA |         1          1        400        400          9         32 |     1,437 
            COLORADO |         1          1        246          7          6          1 |       492 
         CONNECTICUT |         1          1        226        230         19         18 |     1,397 
            DELAWARE |         1          1         23         25          1          0 |       111 
DISTRICT OF COLUMBIA |         0          0         15         15         15          0 |        78 
             FLORIDA |         1          1        276        279        280         22 |     1,548 
             GEORGIA |         1          1        283          8          1          3 |     1,267 
               IDAHO |         1          1        169        170          1          6 |       492 
            ILLINOIS |         1          1        306          0          3         61 |       846 
             INDIANA |         1          1        162        162        166          2 |       683 
                IOWA |         1          1        423        423        423        114 |     2,175 
              KANSAS |         1          1        186        189         58         55 |       769 
            KENTUCKY |         1          1        215        219          0          0 |       767 
           LOUISIANA |         1          1        184        203        203         44 |     1,301 
               MAINE |         1          1        168        168        168          2 |     1,256 
            MARYLAND |         1          1        196         45         49         65 |       674 
       MASSACHUSETTS |         1          1        427        427          5          1 |     1,370 
            MICHIGAN |         1          1        373        374         14         29 |     1,280 
           MINNESOTA |         1          1        148          1          0          4 |       289 
         MISSISSIPPI |         1          1        163        170          2          0 |       497 
            MISSOURI |         1          1        153        153          2          1 |       537 
             MONTANA |         1          1        196         16          0          0 |       308 
            NEBRASKA |         1          1         89         89          0          2 |       243 
              NEVADA |         1          1        151        152          0          0 |       701 
       NEW HAMPSHIRE |         1          1        118        118          0          0 |       489 
          NEW JERSEY |         1          1        169        181         40         34 |       704 
          NEW MEXICO |         1          1        262         27          4          0 |       537 
            NEW YORK |         1          1        315          2          0         20 |       760 
      NORTH CAROLINA |         1          1        158        159         46         21 |       840 
        NORTH DAKOTA |         1          1        110        110          1          1 |       252 
                OHIO |         1          1        401        397         77          0 |     1,407 
            OKLAHOMA |         1          1        247        425        216        220 |     1,762 
              OREGON |         1          1        202        202          0          1 |       940 
        PENNSYLVANIA |         1          1        749      1,532        287         84 |     4,911 
        RHODE ISLAND |         1          1         42         42         42          0 |       278 
      SOUTH CAROLINA |         1          1        141        141          2          0 |       431 
        SOUTH DAKOTA |         1          1        134        134          5          0 |       528 
           TENNESSEE |         1          1        252        252          0          0 |     1,274 
               TEXAS |         1          1        406          3          1          9 |     1,487 
                UTAH |         1          1        289        290          1          3 |     1,019 
             VERMONT |         1          1         90         56          0          0 |       188 
            VIRGINIA |         1          1        243        243          5          0 |     1,073 
          WASHINGTON |         1          1        199          2          1          0 |       426 
       WEST VIRGINIA |         1          1        383        400          0         20 |     1,234 
           WISCONSIN |         1          1        164        164        165          3 |       930 
             WYOMING |         1          1        121        123         49          9 |       389 
---------------------+------------------------------------------------------------------+----------
               Total |        48         48     10,815      9,373      2,435        952 |    44,521 


                     |                             Book year
     State fips code |      1992       1993       1994       1995       1996       1997 |     Total
---------------------+------------------------------------------------------------------+----------
             ALABAMA |        11         48          8          0          1          0 |       439 
             ARIZONA |         2         57          0          4        417          0 |     1,064 
            ARKANSAS |        26         29         42          5          2          5 |       641 
          CALIFORNIA |        21        239          7          4         12         19 |     1,437 
            COLORADO |        22         52          7         11          4          2 |       492 
         CONNECTICUT |        25        128          6        285        273         15 |     1,397 
            DELAWARE |         0         33          0          4          0          0 |       111 
DISTRICT OF COLUMBIA |         0         15          0          0          0          0 |        78 
             FLORIDA |         2        138         70         15         62         49 |     1,548 
             GEORGIA |        24        139        131         96         97         96 |     1,267 
               IDAHO |        10          0          0          0          0          2 |       492 
            ILLINOIS |        76        221         92         10          3          1 |       846 
             INDIANA |         9          2         60          5          2          4 |       683 
                IOWA |        39        392         23         55         46         22 |     2,175 
              KANSAS |        76        100          3          2          3          3 |       769 
            KENTUCKY |        10         84          5          1          1          0 |       767 
           LOUISIANA |        65        104         46         43         34         18 |     1,301 
               MAINE |         1         12         64          6          6          7 |     1,256 
            MARYLAND |        51        144          4         10          7          2 |       674 
       MASSACHUSETTS |         0        300         16          0          4         10 |     1,370 
            MICHIGAN |        48        156         86         80          1          0 |     1,280 
           MINNESOTA |         2         53          0          0          1          1 |       289 
         MISSISSIPPI |         5         35          0         10          5          4 |       497 
            MISSOURI |         9         62          3          0          0          0 |       537 
             MONTANA |         6         29          6          6          6          0 |       308 
            NEBRASKA |         4         22          8          0          0          0 |       243 
              NEVADA |        11        158        156         18         13          1 |       701 
       NEW HAMPSHIRE |         3          3          0          0          0          0 |       489 
          NEW JERSEY |         9          8        135          6          4          6 |       704 
          NEW MEXICO |         8          1         47          2          0          1 |       537 
            NEW YORK |        13        235          4          6          4          4 |       760 
      NORTH CAROLINA |        51        103         10         21          7          4 |       840 
        NORTH DAKOTA |         1          1          0          0          0          9 |       252 
                OHIO |         7        242         39          2          4          0 |     1,407 
            OKLAHOMA |         9        441          0         20          0          0 |     1,762 
              OREGON |         2         54          1          0          0          0 |       940 
        PENNSYLVANIA |       163        666          0         28        119         65 |     4,911 
        RHODE ISLAND |         3         36          0          0          0         46 |       278 
      SOUTH CAROLINA |         2         55         21          4          0          0 |       431 
        SOUTH DAKOTA |         0        117          3          5          2         16 |       528 
           TENNESSEE |       253        253          3          5         21         25 |     1,274 
               TEXAS |         2         27        129        151        135         15 |     1,487 
                UTAH |        28         94          2          1          3          0 |     1,019 
             VERMONT |         2          0          0          0          0          0 |       188 
            VIRGINIA |         1        135         25          0          0          0 |     1,073 
          WASHINGTON |        47         52          0          0          0          0 |       426 
       WEST VIRGINIA |         0         13          0          5          0          0 |     1,234 
           WISCONSIN |        11         45          5          3         19          0 |       930 
             WYOMING |        18          2         27          0          0          0 |       389 
---------------------+------------------------------------------------------------------+----------
               Total |     1,188      5,335      1,294        929      1,318        452 |    44,521 


                     |                             Book year
     State fips code |      1998       1999       2000       2001       2002       2003 |     Total
---------------------+------------------------------------------------------------------+----------
             ALABAMA |         0         22          3          0          2          0 |       439 
             ARIZONA |         0          0          0         29          1         66 |     1,064 
            ARKANSAS |         5         14         69          2          1          0 |       641 
          CALIFORNIA |        89          9         17          0          9          8 |     1,437 
            COLORADO |         3         13         10          3          1         27 |       492 
         CONNECTICUT |         2         45         18          2         76          7 |     1,397 
            DELAWARE |         0          0          0          0          1          1 |       111 
DISTRICT OF COLUMBIA |         0         15          1          1          1          0 |        78 
             FLORIDA |        32         70         33         28         51         11 |     1,548 
             GEORGIA |        73         53         25          6          0         11 |     1,267 
               IDAHO |         1         61         21          0          0         14 |       492 
            ILLINOIS |         0         23          0          2          5          1 |       846 
             INDIANA |         2         55          0          0          2          0 |       683 
                IOWA |        20         59         19          3         16         29 |     2,175 
              KANSAS |         7         21         20          5          5          2 |       769 
            KENTUCKY |         0         16          7        127          1         31 |       767 
           LOUISIANA |         6        118          3          2         23         20 |     1,301 
               MAINE |        33        115         52          0          4         10 |     1,256 
            MARYLAND |         3         14          3          3         13         35 |       674 
       MASSACHUSETTS |        16          7          5          0         31         57 |     1,370 
            MICHIGAN |         0         14          1         11          0         43 |     1,280 
           MINNESOTA |         0         19          0          0          1          3 |       289 
         MISSISSIPPI |         4         14          0          4          5         27 |       497 
            MISSOURI |         1          8          0          6          0          5 |       537 
             MONTANA |         0          8          0          0          0         16 |       308 
            NEBRASKA |         0          1          9          0          0          2 |       243 
              NEVADA |         0          2          0          0          0          0 |       701 
       NEW HAMPSHIRE |         0         24         79         32          0         51 |       489 
          NEW JERSEY |         5          9         12          3          1         46 |       704 
          NEW MEXICO |         1         90          7          0         14         12 |       537 
            NEW YORK |         0         30          0          0          8          0 |       760 
      NORTH CAROLINA |        11         51         14          3         30         30 |       840 
        NORTH DAKOTA |         0          0          0          0          0          2 |       252 
                OHIO |         1         86          1          4          1         60 |     1,407 
            OKLAHOMA |         0         59          3          9         10         60 |     1,762 
              OREGON |         0        308         27         27          0          3 |       940 
        PENNSYLVANIA |         3         31         21         88        471        264 |     4,911 
        RHODE ISLAND |        46          1          3          3          0          0 |       278 
      SOUTH CAROLINA |         0          7          0          0          0          8 |       431 
        SOUTH DAKOTA |        24         35          5          1          4          4 |       528 
           TENNESSEE |        26         25         10          3         30         69 |     1,274 
               TEXAS |         3        162          6          5         60        160 |     1,487 
                UTAH |         3        133         65         11         11         16 |     1,019 
             VERMONT |         0          8          0          0          1          0 |       188 
            VIRGINIA |         1        325          4          6         17         10 |     1,073 
          WASHINGTON |         0         33          0          0          0          5 |       426 
       WEST VIRGINIA |         1         15         85          0          7          0 |     1,234 
           WISCONSIN |         6         14        208          0          1         57 |       930 
             WYOMING |        23          0          0          0          0          0 |       389 
---------------------+------------------------------------------------------------------+----------
               Total |       451      2,242        866        429        915      1,283 |    44,521 


                     |                             Book year
     State fips code |      2004       2005       2006       2007       2008       2009 |     Total
---------------------+------------------------------------------------------------------+----------
             ALABAMA |         6         10          1          9         11          1 |       439 
             ARIZONA |        71          1          1          0         49          1 |     1,064 
            ARKANSAS |        10         23         16          3          0          1 |       641 
          CALIFORNIA |        18         43         69          7         11          1 |     1,437 
            COLORADO |         3         34         21          0          5          1 |       492 
         CONNECTICUT |         3          1          3          1          0          1 |     1,397 
            DELAWARE |         0          2          7          0          0          1 |       111 
DISTRICT OF COLUMBIA |         0          0          0          0          0          0 |        78 
             FLORIDA |        49         40          6          6         15          1 |     1,548 
             GEORGIA |        69          9         14         60         55          1 |     1,267 
               IDAHO |         2         19          1          1          0          1 |       492 
            ILLINOIS |        12          6          9          1          0          1 |       846 
             INDIANA |         1          0          0         33          2          1 |       683 
                IOWA |        13         11          6          8         17          1 |     2,175 
              KANSAS |        14          5          0          1          0          1 |       769 
            KENTUCKY |        12          0          3          7         14          1 |       767 
           LOUISIANA |        42         44         20         32         33          1 |     1,301 
               MAINE |       302         42         74          8          0          1 |     1,256 
            MARYLAND |        15          1          0          0          0          1 |       674 
       MASSACHUSETTS |        15         12          7          8          8          1 |     1,370 
            MICHIGAN |        10         13         11          2          0          1 |     1,280 
           MINNESOTA |        28          0          0          8          6          1 |       289 
         MISSISSIPPI |         6          5         15          3          6          1 |       497 
            MISSOURI |        63          4          1         50          2          1 |       537 
             MONTANA |         2          2          1          0          0          1 |       308 
            NEBRASKA |         2          0          1          0          0          1 |       243 
              NEVADA |        21          2          0          0          2          1 |       701 
       NEW HAMPSHIRE |        27          1          2          3         14          1 |       489 
          NEW JERSEY |         2          5          5          3          7          1 |       704 
          NEW MEXICO |        15          0          0          0         32          1 |       537 
            NEW YORK |         0          0         82          9         14          1 |       760 
      NORTH CAROLINA |         4         95          0          4          4          1 |       840 
        NORTH DAKOTA |         2          0          1          0          0          1 |       252 
                OHIO |        45         24          2          0          0          1 |     1,407 
            OKLAHOMA |         0         13         13          3          0          1 |     1,762 
              OREGON |        82          4          6          4          3          1 |       940 
        PENNSYLVANIA |       135         25         12         65         89          1 |     4,911 
        RHODE ISLAND |         0          0          0          0          0          1 |       278 
      SOUTH CAROLINA |         3         23          0          8          2          1 |       431 
        SOUTH DAKOTA |        15          0          0         10          0          1 |       528 
           TENNESSEE |        32          0          0          1          0          1 |     1,274 
               TEXAS |        21         39         43         12         84          1 |     1,487 
                UTAH |        27          1          7          2         18          1 |     1,019 
             VERMONT |         0         17          0          0          0          1 |       188 
            VIRGINIA |        25         15          0          2          2          1 |     1,073 
          WASHINGTON |        31          0          0         24         18          1 |       426 
       WEST VIRGINIA |         0         56        182         18         35          1 |     1,234 
           WISCONSIN |        44          2          2          0          3          1 |       930 
             WYOMING |         0          0          2          1          0          1 |       389 
---------------------+------------------------------------------------------------------+----------
               Total |     1,299        649        646        417        561         48 |    44,521 


                     |                       Book year
     State fips code |      2010       2011       2012       2013       2014 |     Total
---------------------+-------------------------------------------------------+----------
             ALABAMA |         1          1          1          1          1 |       439 
             ARIZONA |         1          1          1          1          1 |     1,064 
            ARKANSAS |         1          1          1          1          1 |       641 
          CALIFORNIA |         1          1          1          1          1 |     1,437 
            COLORADO |         1          1          1          1          1 |       492 
         CONNECTICUT |         1          1          1          1          1 |     1,397 
            DELAWARE |         1          1          1          1          1 |       111 
DISTRICT OF COLUMBIA |         0          0          0          0          0 |        78 
             FLORIDA |         1          1          1          1          1 |     1,548 
             GEORGIA |         1          1          1          1          1 |     1,267 
               IDAHO |         1          1          1          1          1 |       492 
            ILLINOIS |         1          1          1          1          1 |       846 
             INDIANA |         1          1          1          1          1 |       683 
                IOWA |         1          1          1          1          1 |     2,175 
              KANSAS |         1          1          1          1          1 |       769 
            KENTUCKY |         1          1          1          1          1 |       767 
           LOUISIANA |         1          1          1          1          1 |     1,301 
               MAINE |         1          1          1          1          1 |     1,256 
            MARYLAND |         1          1          1          1          1 |       674 
       MASSACHUSETTS |         1          1          1          1          1 |     1,370 
            MICHIGAN |         1          1          1          1          1 |     1,280 
           MINNESOTA |         1          1          1          1          1 |       289 
         MISSISSIPPI |         1          1          1          1          1 |       497 
            MISSOURI |         1          1          1          1          1 |       537 
             MONTANA |         1          1          1          1          1 |       308 
            NEBRASKA |         1          1          1          1          1 |       243 
              NEVADA |         1          1          1          1          1 |       701 
       NEW HAMPSHIRE |         1          1          1          1          1 |       489 
          NEW JERSEY |         1          1          1          1          1 |       704 
          NEW MEXICO |         1          1          1          1          1 |       537 
            NEW YORK |         1          1          1          1          1 |       760 
      NORTH CAROLINA |         1          1          1          1          1 |       840 
        NORTH DAKOTA |         1          1          1          1          1 |       252 
                OHIO |         1          1          1          1          1 |     1,407 
            OKLAHOMA |         1          1          1          1          1 |     1,762 
              OREGON |         1          1          1          1          1 |       940 
        PENNSYLVANIA |         1          1          1          1          1 |     4,911 
        RHODE ISLAND |         1          1          1          1          1 |       278 
      SOUTH CAROLINA |         1          1          1          1          1 |       431 
        SOUTH DAKOTA |         1          1          1          1          1 |       528 
           TENNESSEE |         1          1          1          1          1 |     1,274 
               TEXAS |         1          1          1          1          1 |     1,487 
                UTAH |         1          1          1          1          1 |     1,019 
             VERMONT |         1          1          1          1          1 |       188 
            VIRGINIA |         1          1          1          1          1 |     1,073 
          WASHINGTON |         1          1          1          1          1 |       426 
       WEST VIRGINIA |         1          1          1          1          1 |     1,234 
           WISCONSIN |         1          1          1          1          1 |       930 
             WYOMING |         1          1          1          1          1 |       389 
---------------------+-------------------------------------------------------+----------
               Total |        48         48         48         48         48 |    44,521 

. *drop state-years with no resurfacing expenditure;
. drop if exp_IRI_IH_SF12a_r==0;
(5,758 observations deleted)

. drop if exp_IRI_IH_SF12a_r==.;
(0 observations deleted)

. *drop id-years with bad IRI data;
. drop if Diri==.;
(41,806 observations deleted)

. drop if abs(Diri)>200;
(344 observations deleted)

. *drop state-years with no resurfacing;
. drop if lane_milesI2_st==.|lane_milesI2_st==0;
(50,587 observations deleted)

. *drop DC and years outside sample;
. drop if state==11;
(0 observations deleted)

. drop if year<1992;
(23,548 observations deleted)

. drop if year>2008;
(0 observations deleted)

. tab state;

     State fips code |      Freq.     Percent        Cum.
---------------------+-----------------------------------
             ALABAMA |      1,169        0.63        0.63
             ARIZONA |      8,057        4.33        4.96
            ARKANSAS |      1,877        1.01        5.97
          CALIFORNIA |      6,247        3.36        9.33
            COLORADO |      2,132        1.15       10.47
         CONNECTICUT |      3,652        1.96       12.43
            DELAWARE |        171        0.09       12.53
             FLORIDA |      4,462        2.40       14.92
             GEORGIA |      3,607        1.94       16.86
               IDAHO |      2,799        1.50       18.37
            ILLINOIS |      3,718        2.00       20.37
                IOWA |      3,932        2.11       22.48
              KANSAS |      1,762        0.95       23.43
            KENTUCKY |      2,749        1.48       24.90
           LOUISIANA |      2,098        1.13       26.03
               MAINE |      2,057        1.11       27.14
            MARYLAND |      4,420        2.38       29.51
       MASSACHUSETTS |      2,135        1.15       30.66
            MICHIGAN |      4,737        2.55       33.21
           MINNESOTA |      2,251        1.21       34.42
         MISSISSIPPI |      1,197        0.64       35.06
            MISSOURI |      1,555        0.84       35.89
             MONTANA |      2,911        1.56       37.46
            NEBRASKA |      1,643        0.88       38.34
              NEVADA |      1,363        0.73       39.08
       NEW HAMPSHIRE |      1,884        1.01       40.09
          NEW JERSEY |      2,593        1.39       41.48
          NEW MEXICO |      2,201        1.18       42.66
            NEW YORK |      5,272        2.83       45.50
      NORTH CAROLINA |      4,507        2.42       47.92
        NORTH DAKOTA |      1,623        0.87       48.79
                OHIO |      7,468        4.01       52.81
            OKLAHOMA |      2,488        1.34       54.14
              OREGON |      5,303        2.85       56.99
        PENNSYLVANIA |     47,182       25.36       82.35
        RHODE ISLAND |        325        0.17       82.53
      SOUTH CAROLINA |      1,111        0.60       83.12
        SOUTH DAKOTA |      2,865        1.54       84.66
           TENNESSEE |      2,181        1.17       85.84
               TEXAS |      7,085        3.81       89.64
                UTAH |      2,588        1.39       91.04
             VERMONT |      1,326        0.71       91.75
            VIRGINIA |      2,191        1.18       92.93
          WASHINGTON |      2,366        1.27       94.20
       WEST VIRGINIA |      6,434        3.46       97.66
           WISCONSIN |      2,491        1.34       98.99
             WYOMING |      1,870        1.01      100.00
---------------------+-----------------------------------
               Total |    186,055      100.00

. *aadt variables;
.         gen aadt2_10000=aadt_1000^2;

. label var aadt2_10000 "(`:  var label aadt_1000')^2" ;

. gen aadt3_10000=aadt_1000^3;

. label var aadt3_10000 "(`:  var label aadt_1000')^3" ;

.         *Set up state year and I2 x year FE;
. *calculate number of years that each state is present in data;
. preserve;

.         sort state year;

.         by state year: gen counter1=_n;

.         keep if counter1==1;
(185,480 observations deleted)

.         display "count number of stateXyears for reference";
count number of stateXyears for reference

.         sum year;

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
        year |        575     1999.61    4.837559       1992       2008

.         sort state;

.         by state: gen num_years=_N;

.         by state: gen counter3=_n;

.         keep if counter3==1;
(528 observations deleted)

.         label var num_years "Years state present in data";

.         keep state num_years;

.         tab num_years;

Years state |
 present in |
       data |      Freq.     Percent        Cum.
------------+-----------------------------------
          5 |          2        4.26        4.26
          6 |          1        2.13        6.38
          7 |          2        4.26       10.64
          8 |          3        6.38       17.02
          9 |          5       10.64       27.66
         10 |          6       12.77       40.43
         12 |          2        4.26       44.68
         13 |          2        4.26       48.94
         14 |         10       21.28       70.21
         15 |          5       10.64       80.85
         16 |          2        4.26       85.11
         17 |          7       14.89      100.00
------------+-----------------------------------
      Total |         47      100.00

.         display "states present 1990-2008 --- use Texas 1990 for omitted state-year";
states present 1990-2008 --- use Texas 1990 for omitted state-year

.         tab state if num_years==18;
no observations

.         tab state if num_years==18, nol;
no observations

. // Texas, fips 48 is present in all years
>         sort state;

.         save stateyears,replace;
(file stateyears.dta not found)
file stateyears.dta saved

. restore;

. merge m:1 state using stateyears;
(label fips already defined)

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                           186,055  (_merge==3)
    -----------------------------------------

. tab _merge;

   Matching result from |
                  merge |      Freq.     Percent        Cum.
------------------------+-----------------------------------
            Matched (3) |    186,055      100.00      100.00
------------------------+-----------------------------------
                  Total |    186,055      100.00

. order state state_name year num_years;

. erase stateyears.dta;

. *make state-year indicators for state years present in data;
.         levelsof year, local(year_list);
1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008

. levelsof state, local(state_list);
1 4 5 6 8 9 10 12 13 16 17 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 45 46
>  47 48 49 50 51 53 54 55 56

. display "`state_list'";
1 4 5 6 8 9 10 12 13 16 17 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 45 46
>  47 48 49 50 51 53 54 55 56

. display "`year_list'";
1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008

. local i_stateyear=1;

. foreach k_year of local year_list{;
  2.         foreach k_state of local state_list{;
  3.                 if !("`k_year'"=="1990"&"`k_state'"=="48"){;
  4.  //texas 1990 omitted
>                         *make dummy for state-year;
.                         gen stateXyearI_`k_year'_`k_state'=cond(year==`k_year'&state==`k_state',1,0);
  5.                         *drop indicator if state-year missing from data;
.                         quiet sum stateXyearI_`k_year'_`k_state';
  6.                         local tester =r(mean) ;
  7.                         if `tester'==0{;
  8.                                 drop stateXyearI_`k_year'_`k_state';
  9.                                 };
 10.                         *increment counter if state-year present in data. counter is just used as a di
> agnostic;
.                         if `tester'>0{;
 11.                                 local ++i_stateyear;
 12.                                 };
 13.                         };
 14. //end skip texas 1990 if
>                 };
 15. //end state loop
>         };

. //end year loop
> display "`i_stateyear'-1 state-year indicators created -- should match tab above";
576-1 state-year indicators created -- should match tab above

. *make year X I2_t indicators and year X I2_t * expenditure per mile variables;
.         levelsof year, local(year_list);
1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008

. display "`year_list'";
1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008

. foreach k_year of local year_list{;
  2.         gen I2_t_x`k_year'                      =cond(year==`k_year'& I2_t==1,1,0);
  3.         gen I2_t_`k_year'_exp_I2        =I2_t_x`k_year'*exp_IRI_IH_SF12a_plm;
  4.         gen I2_t_`k_year'_exp_L         =I2_t_x`k_year'*exp_L_IH_I2_SF12a_plm;
  5.                         label var I2_t_`k_year'_exp_I2          "IRI exp per I2 lane mile `k_year'";
  6.         label var I2_t_`k_year'_exp_L           "L exp per I2 lane mile `k_year'";
  7.         };

. //end year loop
> 
>         
>         
> gen urban=1 if  D_urban==1 | D_small_urban==1;
(91,747 missing values generated)

. replace urban =0 if D_rural==1 ;
(91,747 real changes made)

. label var urban "Dummy=1 if urban" ;

.                                         * time, for estimating trends;
. gen time =year-1990;

. gen time2 =time^2;

. gen time3 =time^3;

. label var time2 "\(time^2\)" ;

. label var time3 "\(time^3\)" ;

. *TIME TREND DUMMIES;
. gen     periods=1 if  year>=1984&year<=1989;
(186,055 missing values generated)

. replace periods=2 if  year>=1990&year<=1994;
(28,365 real changes made)

. replace periods=3 if  year>=1995&year<=1999;
(55,231 real changes made)

. replace periods=4 if  year>=2000&year<=2004;
(58,770 real changes made)

. replace periods=5 if  year>=2005&year<=2008;
(43,689 real changes made)

. tab year periods, m ;

           |                   periods
 Book year |         2          3          4          5 |     Total
-----------+--------------------------------------------+----------
      1992 |    10,524          0          0          0 |    10,524 
      1993 |     6,932          0          0          0 |     6,932 
      1994 |    10,909          0          0          0 |    10,909 
      1995 |         0     10,735          0          0 |    10,735 
      1996 |         0     11,646          0          0 |    11,646 
      1997 |         0     11,080          0          0 |    11,080 
      1998 |         0     11,326          0          0 |    11,326 
      1999 |         0     10,444          0          0 |    10,444 
      2000 |         0          0     11,846          0 |    11,846 
      2001 |         0          0     12,857          0 |    12,857 
      2002 |         0          0     10,956          0 |    10,956 
      2003 |         0          0     11,547          0 |    11,547 
      2004 |         0          0     11,564          0 |    11,564 
      2005 |         0          0          0     10,878 |    10,878 
      2006 |         0          0          0     10,944 |    10,944 
      2007 |         0          0          0     10,840 |    10,840 
      2008 |         0          0          0     11,027 |    11,027 
-----------+--------------------------------------------+----------
     Total |    28,365     55,231     58,770     43,689 |   186,055 

. label define periods 1 "1984-1989"
>                                         2 "1990-1994"
>                                         3 "1995-1999"
>                                         4 "2000-2004"
>                                         5 "2005-2008";

. label values periods periods;

. *** Gen state_year to cluster standar errors ;
. egen state_year= group(state year);

. *make I2_t * expenditure per mile variables;
.         foreach I in Ids_t Iall_t I2_t{;
  2.         gen `I'_exp_I2          =`I'*exp_IRI_IH_SF12a_plm;
  3.         gen `I'_exp_L           =`I'*exp_L_IH_I2_SF12a_plm;
  4.         gen `I'_app_I2                  =`I'*app_IH_I2_plm ;
  5.                 forvalues i=1(1)5{;
  6.                 gen `I'_L`i'_apport_I2=`I'*L`i'FHWA_apport_LW_r_plm;
  7.         };
  8.                         *LABEL FOR TEX OUPTU;
.         label var `I'_exp_I2            "\( \mathds{1}_{ist}(q)\imath^q_{st}\)";
  9. };
(17,456 missing values generated)
(17,456 missing values generated)
(17,456 missing values generated)

.         # d cr ;
delimiter now cr
.         
. 
end of do-file

. do "_programs_sample";

. # d ;
delimiter now ;
. ****************************************;
.         *This program is used to add a row indicating the use of sample id when using areg;
. cap program drop add_lab_FE;

. program define add_lab_FE;
  1.         matrix V = [vecdiag(e(V)),1];
  2.         matrix V=diag(V);
  3.         matrix b=[e(b),1];
  4.         matrix colnames b= `:  colnames e(b)' `1';
  5.         matrix colnames V= `:  colnames e(V)' `1';
  6.         erepost b=b V=V ,rename;
  7. end;

. ****************************************;
.         *This program calculates summary stats for regression tables;
. cap program drop sum_stats;

. program define sum_stats;
  1.         sum Diri ;
  2.         estadd  scalar mean_Diri=r(mean) ;
  3.         sum aadt_10000  ;
  4.         estadd  scalar mean_aadt=r(mean) ;
  5.         sum I2_t ;
  6.         estadd  scalar mean_I2_t=r(mean) ;
  7.         sum I2_t_exp_I2  ;
  8.         estadd  scalar mean_I2_t_exp=r(mean) ;
  9.         end;

. ****************************************;
.         *This program plots year dummies;
. cap program drop plot_dummies;

. program define plot_dummies;
  1.         preserve;
  2.         *save se to disk;
.         mata: se=sqrt(diagonal(st_matrix("e(V)")));
  3.  // converts e(V) into se and placed in mata matrix se
>         clear;
  4.         getmata se, force ;
  5.         gen counter=_n;
  6.         save se,replace;
  7.                 *save coefficients to disk and organize;
.         mat beta=e(b);
  8.         mat list beta;
  9.         clear;
 10.         set obs 1;
 11.         svmat double beta;
 12.         *file in memory is a single row year effects from regression;
.         gen dummy=1;
 13.         reshape long beta,  i(dummy) j(year);
 14.         gen counter=_n;
 15.         *merge with se;
.         merge 1:1 counter using se;
 16.         drop if counter>17;
 17.         drop if beta==. | beta==0;
 18.         drop _merge counter;
 19.         *just keep year X expenditure coefficients;
.         drop if year==.;
 20.         replace year = year+1991;
 21.         sort year;
 22.         *file in memory gives bin, mean y and se;
.         gen up5 = beta+1.96*se;
 23.         gen down5 = beta-1.96*se;
 24.         save beta, replace;
 25.         *file in memory is a list of year by year inverse prices and CI's;
.         *settings for plots;
.         local pdf_plot_settings =       `"bgcolor(white) 
>                                         graphregion(color(white)) plotregion(ls(none))  
>                                                                 xmtick(1992(1)2008) 
>                                                                 ymtick(##5)
>                                                                 xlabel(1992(4)2008)
>                                         xtitle("")
>                                         legend(off)
>                                         scale(*1.5)
>                                         
>                                         "';
 26.                                         twoway rcap up5 down5 year, lstyle(ci)|| scatter beta year, `p
> df_plot_settings';
 27.         graph export "temp_t.pdf", replace;
 28.         erase se.dta;
 29.         erase beta.dta;
 30.         save "temp_betas.dta", replace;
 31.         restore;
 32. end;

. # d ;
delimiter now ;
. cap program drop plot_dummies_cons;

. program define plot_dummies_cons;
  1. args y_var controls;
  2.         matrix time_cons=J(17,3,.);
  3.         matrix colnames time_cons=year beta var;
  4.         local n=1;
  5.                 if "`controls'"==""{;
  6.                 forvalues year=1992(1)2008{;
  7.                                 reg `y_var' I2_t_x* ,  cluster(state);
  8.                                 nlcom _b[I2_t_x`year']+_b[_cons], post;
  9.                                 mat  time_cons[`n',1]=`year';
 10.                                 mat  time_cons[`n',2]=e(b);
 11.                                 mat  time_cons[`n',3]=e(V);
 12.                                 local n=`n'+1;
 13.                 }               ;
 14.         };
 15.                                         if "`controls'"=="state"{;
 16.                 forvalues year=1992(1)2008{;
 17.                                                                 areg Diri  I2_t_x*   ,  cluster(state)
>  abs(state ) ;
 18. ;
.                                 nlcom _b[I2_t_x`year']+_b[_cons], post;
 19.                                 mat  time_cons[`n',1]=`year';
 20.                                 mat  time_cons[`n',2]=e(b);
 21.                                 mat  time_cons[`n',3]=e(V);
 22.                                 local n=`n'+1;
 23.                 }               ;
 24.         };
 25.                                 if "`controls'"=="id"{;
 26.                 forvalues year=1992(1)2008{;
 27.                                                                 areg Diri  I2_t_x*   ,  cluster(state)
>  abs(id) ;
 28.                                 nlcom _b[I2_t_x`year']+_b[_cons], post;
 29.                                 mat  time_cons[`n',1]=`year';
 30.                                 mat  time_cons[`n',2]=e(b);
 31.                                 mat  time_cons[`n',3]=e(V);
 32.                                 local n=`n'+1;
 33.                 }               ;
 34.         };
 35.                                         preserve ;
 36.                                 clear ;
 37.                                 svmat time_cons, names(col) ;
 38.                                 gen se=var^(1/2);
 39.                                 gen up5 = beta+1.96*se;
 40.                                 gen down5 = beta-1.96*se;
 41.                                 save beta`y_var', replace;
 42.                                 *file in memory is a list of year by year inverse prices and CI's;
.                                 *settings for plots;
.                                 local pdf_plot_settings =       `"bgcolor(white) 
>                                                                 graphregion(color(white)) plotregion(ls(n
> one))  
>                                                                 xmtick(1992(1)2008) 
>                                                                 ymtick(##5)
>                                                                 xlabel(1992(4)2008)
>                                                                 legend(off)
>                                                                 xtitle("")
>                                                                 
>                                                                 scale(*1.5)"';
 43.                                 twoway rcap up5 down5 year, lstyle(ci)|| scatter beta year, `pdf_plot_
> settings';
 44.                                 graph export "temp_t.pdf", replace;
 45.                                                                                         restore ;
 46. end;

. # d cr ;
delimiter now cr
. 
. 
end of do-file

. ** generate a variable of average number of years between maintenance in a segment;
. bysort id (year): egen N_maint=total(I2_t);

. bysort id (year): egen xx=count(year);

. gen av_year_maint=xx/(N_maint+1);

. label var av_year_maint "mean t for I in seg i";

. tab av_year_maint;

 mean t for |
 I in seg i |      Freq.     Percent        Cum.
------------+-----------------------------------
         .5 |        239        0.13        0.13
   .6666667 |          4        0.00        0.13
        .75 |          3        0.00        0.13
          1 |      4,845        2.60        2.74
       1.25 |         15        0.01        2.74
   1.333333 |         36        0.02        2.76
        1.5 |        468        0.25        3.02
   1.666667 |         50        0.03        3.04
       1.75 |         42        0.02        3.06
          2 |      4,274        2.30        5.36
   2.166667 |         13        0.01        5.37
       2.25 |         36        0.02        5.39
   2.333333 |        154        0.08        5.47
        2.5 |      1,335        0.72        6.19
   2.666667 |        400        0.21        6.40
       2.75 |         22        0.01        6.42
        2.8 |         14        0.01        6.42
          3 |      5,379        2.89        9.31
       3.25 |        156        0.08        9.40
   3.333333 |        670        0.36        9.76
        3.4 |         51        0.03        9.79
        3.5 |      2,016        1.08       10.87
   3.666667 |        209        0.11       10.98
       3.75 |        210        0.11       11.09
          4 |     10,652        5.73       16.82
       4.25 |        612        0.33       17.15
   4.333333 |      1,157        0.62       17.77
        4.5 |      3,483        1.87       19.64
   4.666667 |      1,652        0.89       20.53
          5 |     10,405        5.59       26.12
   5.333333 |        384        0.21       26.33
        5.5 |      2,695        1.45       27.78
   5.666667 |      5,100        2.74       30.52
          6 |     12,486        6.71       37.23
        6.5 |      4,706        2.53       39.76
          7 |     11,816        6.35       46.11
        7.5 |      8,670        4.66       50.77
          8 |     10,552        5.67       56.44
        8.5 |     14,331        7.70       64.14
          9 |      8,478        4.56       68.70
         10 |      5,440        2.92       71.62
         11 |      4,818        2.59       74.21
         12 |      9,228        4.96       79.17
         13 |      5,408        2.91       82.08
         14 |      7,000        3.76       85.84
         15 |     10,350        5.56       91.41
         16 |      2,000        1.07       92.48
         17 |     13,991        7.52      100.00
------------+-----------------------------------
      Total |    186,055      100.00

. drop  xx;

. *------------------------------------------------;
.  *regressions;
.  *-----------------------------------------------;
. tab year;

  Book year |      Freq.     Percent        Cum.
------------+-----------------------------------
       1992 |     10,524        5.66        5.66
       1993 |      6,932        3.73        9.38
       1994 |     10,909        5.86       15.25
       1995 |     10,735        5.77       21.02
       1996 |     11,646        6.26       27.27
       1997 |     11,080        5.96       33.23
       1998 |     11,326        6.09       39.32
       1999 |     10,444        5.61       44.93
       2000 |     11,846        6.37       51.30
       2001 |     12,857        6.91       58.21
       2002 |     10,956        5.89       64.10
       2003 |     11,547        6.21       70.30
       2004 |     11,564        6.22       76.52
       2005 |     10,878        5.85       82.36
       2006 |     10,944        5.88       88.25
       2007 |     10,840        5.83       94.07
       2008 |     11,027        5.93      100.00
------------+-----------------------------------
      Total |    186,055      100.00

. local listcontinous "c.time cont Baseline" ;

. local listcontinous2 "c.time_+_c.time2 cont_2 " ;

. local listdiscrete  "ib2.periods dum Periods" ;

. gen no_trucks_aadt=aadt_10000 - trucks_av_10000;

. label var no_trucks_aadt "No trucks AADT/10000";

. label var trucks_av_10000 "Trucks AADT/10000";

. local keep_rule "if 1==1 ";

. local keep_rule_all "if 1==1 ";

. local keep_rule_after1992 "if year>1992" ;

. ren unionization_*   union_*;

. tab year;

  Book year |      Freq.     Percent        Cum.
------------+-----------------------------------
       1992 |     10,524        5.66        5.66
       1993 |      6,932        3.73        9.38
       1994 |     10,909        5.86       15.25
       1995 |     10,735        5.77       21.02
       1996 |     11,646        6.26       27.27
       1997 |     11,080        5.96       33.23
       1998 |     11,326        6.09       39.32
       1999 |     10,444        5.61       44.93
       2000 |     11,846        6.37       51.30
       2001 |     12,857        6.91       58.21
       2002 |     10,956        5.89       64.10
       2003 |     11,547        6.21       70.30
       2004 |     11,564        6.22       76.52
       2005 |     10,878        5.85       82.36
       2006 |     10,944        5.88       88.25
       2007 |     10,840        5.83       94.07
       2008 |     11,027        5.93      100.00
------------+-----------------------------------
      Total |    186,055      100.00

. local time              = word("`listcontinous'",1) ;

. local time `:subinstr local time `"_+_"' `" "', ';

. local name              = word("`listcontinous'",2);

. local title         = word("`listcontinous'",2);

.         local titleD_rig         "Rigid surface";

. local titlesh_elev_10m_s "Elevation" ;

. local titlesh_urb_10m_s  "NLCD Urban";

. local titleurban         "HPMS Urban";

. local titleaadt_10000    "AADT";

. local titleD_rig                 "Rigid surface";

. local titlesn_d          "Structural Number";

. local titleaverage_grade_seg "Average Grade";

. local titlesh_h20_10m_s  "NLCD Water";

. local titleunion_Mem_Total    "Unionization";

. local cluster_var   state_year ;

. global main_var aadt_10000 urban sh_urb_10m_s D_rig sn_d union_Mem_Total;

.  global appendix_var   average_grade_seg sh_elev_10m_s sh_h20_10m_s;

.         local tit_state "State";

. local tit_state_year "State-Year";

. global SE_note "Standard Errors in Parentheses Clustered at the `tit_`cluster_var'' Level";

.                                                 foreach comp_var of global main_var                     {
> ;
  2.                                 gen comp_temp = `comp_var';
  3.                                 label var comp_temp "x";
  4.  //clear labels that cause formatting problems for estout ;20
>                                 eststo ,prefix(`comp_var'_): reghdfe    Diri  I2_t_exp_I2 c.I2_t_exp_I2#(
> `time') `time'
>                                                                                                         c
> .comp_temp c.comp_temp#c.I2_t_exp_I2 c.comp_temp#c.I2_t_exp_I2#(`time') 
>                                                                                                          
> ,  absor( id)  cluster(`cluster_var');
  5.                                 drop comp_temp;
  6.                                 estfe . `comp_var'_*, labels( id "Segment id FE");
  7.                                                         };
(dropped 4819 singleton observations)
(MWFE estimator converged in 1 iterations)

HDFE Linear regression                            Number of obs   =    181,236
Absorbing 1 HDFE group                            F(   6,    572) =      57.64
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.1207
                                                  Adj R-squared   =     0.0102
                                                  Within R-sq.    =     0.0682
Number of clusters (state_year) =        573      Root MSE        =    25.6594

                                               (Std. err. adjusted for 573 clusters in state_year)
--------------------------------------------------------------------------------------------------
                                 |               Robust
                            Diri | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
---------------------------------+----------------------------------------------------------------
                     I2_t_exp_I2 |  -1076.502   127.3595    -8.45   0.000    -1326.652    -826.353
                                 |
            c.I2_t_exp_I2#c.time |   28.56352    8.58015     3.33   0.001     11.71108    45.41597
                                 |
                            time |   .0370405   .0809645     0.46   0.647    -.1219835    .1960644
                       comp_temp |  -.3762351   .1973539    -1.91   0.057    -.7638619    .0113916
                                 |
       c.comp_temp#c.I2_t_exp_I2 |   24.57628   14.62129     1.68   0.093    -4.141688    53.29425
                                 |
c.comp_temp#c.I2_t_exp_I2#c.time |  -.2872255   .9169652    -0.31   0.754    -2.088255    1.513804
                                 |
                           _cons |   .9141376    1.22354     0.75   0.455    -1.489041    3.317317
--------------------------------------------------------------------------------------------------

Absorbed degrees of freedom:
-----------------------------------------------------+
 Absorbed FE | Categories  - Redundant  = Num. Coefs |
-------------+---------------------------------------|
          id |     20221           0       20221     |
-----------------------------------------------------+
(aadt_10000_1 stored)
(dropped 4819 singleton observations)
note: comp_temp is probably collinear with the fixed effects (all partialled-out values are close to zero; 
> tol = 1.0e-09)
(MWFE estimator converged in 1 iterations)
note: comp_temp omitted because of collinearity

HDFE Linear regression                            Number of obs   =    181,236
Absorbing 1 HDFE group                            F(   5,    572) =      71.32
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.1203
                                                  Adj R-squared   =     0.0098
                                                  Within R-sq.    =     0.0678
Number of clusters (state_year) =        573      Root MSE        =    25.6653

                                               (Std. err. adjusted for 573 clusters in state_year)
--------------------------------------------------------------------------------------------------
                                 |               Robust
                            Diri | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
---------------------------------+----------------------------------------------------------------
                     I2_t_exp_I2 |  -1005.197   126.0789    -7.97   0.000    -1252.831   -757.5626
                                 |
            c.I2_t_exp_I2#c.time |   25.19037   8.217829     3.07   0.002     9.049569    41.33117
                                 |
                            time |   .0037343   .0779101     0.05   0.962    -.1492904    .1567591
                       comp_temp |          0  (omitted)
                                 |
       c.comp_temp#c.I2_t_exp_I2 |   26.97683   136.3751     0.20   0.843    -240.8803     294.834
                                 |
c.comp_temp#c.I2_t_exp_I2#c.time |   10.68428     9.4531     1.13   0.259    -7.882746     29.2513
                                 |
                           _cons |  -.5215224   .9967233    -0.52   0.601    -2.479207    1.436162
--------------------------------------------------------------------------------------------------

Absorbed degrees of freedom:
-----------------------------------------------------+
 Absorbed FE | Categories  - Redundant  = Num. Coefs |
-------------+---------------------------------------|
          id |     20221           0       20221     |
-----------------------------------------------------+
(urban_2 stored)
(dropped 4819 singleton observations)
note: comp_temp is probably collinear with the fixed effects (all partialled-out values are close to zero; 
> tol = 1.0e-09)
(MWFE estimator converged in 1 iterations)
note: comp_temp omitted because of collinearity

HDFE Linear regression                            Number of obs   =    181,236
Absorbing 1 HDFE group                            F(   5,    572) =      63.58
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.1235
                                                  Adj R-squared   =     0.0134
                                                  Within R-sq.    =     0.0712
Number of clusters (state_year) =        573      Root MSE        =    25.6179

                                               (Std. err. adjusted for 573 clusters in state_year)
--------------------------------------------------------------------------------------------------
                                 |               Robust
                            Diri | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
---------------------------------+----------------------------------------------------------------
                     I2_t_exp_I2 |  -1662.475    220.562    -7.54   0.000    -2095.685   -1229.265
                                 |
            c.I2_t_exp_I2#c.time |   55.59595   15.46205     3.60   0.000     25.22663    85.96528
                                 |
                            time |  -.0031601   .0774126    -0.04   0.967    -.1552077    .1488876
                       comp_temp |          0  (omitted)
                                 |
       c.comp_temp#c.I2_t_exp_I2 |   4504.982   980.2428     4.60   0.000     2579.668    6430.296
                                 |
c.comp_temp#c.I2_t_exp_I2#c.time |  -166.7948   75.37915    -2.21   0.027    -314.8485    -18.7411
                                 |
                           _cons |  -.4124053   .9901427    -0.42   0.677    -2.357164    1.532354
--------------------------------------------------------------------------------------------------

Absorbed degrees of freedom:
-----------------------------------------------------+
 Absorbed FE | Categories  - Redundant  = Num. Coefs |
-------------+---------------------------------------|
          id |     20221           0       20221     |
-----------------------------------------------------+
(sh_urb_10m_s_3 stored)
(167 missing values generated)
(dropped 4820 singleton observations)
(MWFE estimator converged in 1 iterations)

HDFE Linear regression                            Number of obs   =    181,068
Absorbing 1 HDFE group                            F(   6,    571) =      48.69
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.1207
                                                  Adj R-squared   =     0.0102
                                                  Within R-sq.    =     0.0683
Number of clusters (state_year) =        572      Root MSE        =    25.6029

                                               (Std. err. adjusted for 572 clusters in state_year)
--------------------------------------------------------------------------------------------------
                                 |               Robust
                            Diri | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
---------------------------------+----------------------------------------------------------------
                     I2_t_exp_I2 |  -928.0026   99.30554    -9.34   0.000    -1123.051   -732.9538
                                 |
            c.I2_t_exp_I2#c.time |   26.26934    7.32673     3.59   0.000     11.87871    40.65997
                                 |
                            time |    .049576   .0762648     0.65   0.516    -.1002177    .1993696
                       comp_temp |   3.540575   1.166317     3.04   0.003      1.24978    5.831371
                                 |
       c.comp_temp#c.I2_t_exp_I2 |  -346.8244   168.6468    -2.06   0.040    -678.0681   -15.58075
                                 |
c.comp_temp#c.I2_t_exp_I2#c.time |   19.87984   12.36663     1.61   0.108    -4.409788    44.16947
                                 |
                           _cons |  -2.294283   1.045441    -2.19   0.029    -4.347662    -.240903
--------------------------------------------------------------------------------------------------

Absorbed degrees of freedom:
-----------------------------------------------------+
 Absorbed FE | Categories  - Redundant  = Num. Coefs |
-------------+---------------------------------------|
          id |     20220           0       20220     |
-----------------------------------------------------+
(D_rig_4 stored)
(dropped 4819 singleton observations)
(MWFE estimator converged in 1 iterations)

HDFE Linear regression                            Number of obs   =    181,236
Absorbing 1 HDFE group                            F(   6,    572) =      51.06
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.1202
                                                  Adj R-squared   =     0.0096
                                                  Within R-sq.    =     0.0677
Number of clusters (state_year) =        573      Root MSE        =    25.6669

                                               (Std. err. adjusted for 573 clusters in state_year)
--------------------------------------------------------------------------------------------------
                                 |               Robust
                            Diri | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
---------------------------------+----------------------------------------------------------------
                     I2_t_exp_I2 |  -635.5327   195.7275    -3.25   0.001    -1019.965   -251.1004
                                 |
            c.I2_t_exp_I2#c.time |   14.33929   13.81267     1.04   0.300    -12.79044    41.46903
                                 |
                            time |    .001992   .0780992     0.03   0.980    -.1514041    .1553881
                       comp_temp |   .3680045   .3169473     1.16   0.246    -.2545179    .9905269
                                 |
       c.comp_temp#c.I2_t_exp_I2 |  -53.77311   31.91561    -1.68   0.093    -116.4592    8.912983
                                 |
c.comp_temp#c.I2_t_exp_I2#c.time |   2.391018   2.119408     1.13   0.260    -1.771754     6.55379
                                 |
                           _cons |  -3.153769   2.550725    -1.24   0.217    -8.163698    1.856161
--------------------------------------------------------------------------------------------------

Absorbed degrees of freedom:
-----------------------------------------------------+
 Absorbed FE | Categories  - Redundant  = Num. Coefs |
-------------+---------------------------------------|
          id |     20221           0       20221     |
-----------------------------------------------------+
(sn_d_5 stored)
(dropped 4819 singleton observations)
(MWFE estimator converged in 1 iterations)

HDFE Linear regression                            Number of obs   =    181,236
Absorbing 1 HDFE group                            F(   6,    572) =      53.89
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.1208
                                                  Adj R-squared   =     0.0104
                                                  Within R-sq.    =     0.0684
Number of clusters (state_year) =        573      Root MSE        =    25.6575

                                               (Std. err. adjusted for 573 clusters in state_year)
--------------------------------------------------------------------------------------------------
                                 |               Robust
                            Diri | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
---------------------------------+----------------------------------------------------------------
                     I2_t_exp_I2 |  -1849.195   252.4028    -7.33   0.000    -2344.944   -1353.446
                                 |
            c.I2_t_exp_I2#c.time |   92.80509   16.83496     5.51   0.000     59.73921     125.871
                                 |
                            time |  -.0252548   .1314298    -0.19   0.848    -.2833988    .2328891
                       comp_temp |  -.0920496   .4178579    -0.22   0.826    -.9127726    .7286735
                                 |
       c.comp_temp#c.I2_t_exp_I2 |   50.12032   13.31659     3.76   0.000     23.96493     76.2757
                                 |
c.comp_temp#c.I2_t_exp_I2#c.time |  -3.787615   .9333899    -4.06   0.000    -5.620905   -1.954326
                                 |
                           _cons |    1.05103   6.872377     0.15   0.879    -12.44714     14.5492
--------------------------------------------------------------------------------------------------

Absorbed degrees of freedom:
-----------------------------------------------------+
 Absorbed FE | Categories  - Redundant  = Num. Coefs |
-------------+---------------------------------------|
          id |     20221           0       20221     |
-----------------------------------------------------+
(union_Mem_Total_6 stored)

. return list;

macros:
        r(indicate_fe) : " "Segment id FE=0.id" "

.                                         ***** Main Table  ;
.                                 local tex_settigns  = `"
>                                                                                 ${prehead_start}
>                                                                                 `font_size'
>                                                                                 ${prehead_end_bigskip}
>                                                                                 ${postfoot}
>                                                                                 "';

.                 return list;

macros:
        r(indicate_fe) : " "Segment id FE=0.id" "

.         tokenize `"$main_var"' ;

.  //this will give me the name of the variables in order to put in the table titles;
>         esttab  `1'* `2'* `3'* `4'* `5'* `6'*
>                 using "${output}/tables/Table4_sample_composition.tex", replace
>                 b(%8.2fc) se(%8.2fc)  sfmt(%8.2fc)
>                 order( I2_t_exp_I2)
>                 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) 
>                 note( \noteSampleComposition ${SE_note} )
>                 indicate(   `r(indicate_fe)' )
>                 title("Composition effects resurfacing\label{tab:composition_Q}")
>                 mtitle( "\LongHead{15ex}{`title`1''}"
>                                 "\LongHead{15ex}{`title`2''}"
>                                 "\LongHead{15ex}{`title`3''}"
>                                 "\LongHead{15ex}{`title`4''}"
>                                 "\LongHead{15ex}{`title`5''}"
>                                 "\LongHead{15ex}{`title`6''}"
>                                 )
>                 noomitted   nobaselevels nonumbers
>                         substitute(\_ _ 
>                         "c.comp_temp" "\(x^0\)"
>                         "comp_temp" "\(x^0\)"
>                         "I2_t=1" "\mathds{1}_{ist}(q)"
>                         "Segment id FE" 
>                         "\cline{2-7}Segment id FE"
>                         "time" "\(t\)"
>                         "$\\(t\)s$" "\(\times\)"
>                                                         )
>                 se  par  ar2  r2 label nogaps  drop(_cons) compress
>                 obslast stats(N, fmt(%9.0fc))
>                 `tex_settigns';
(output written to ..//tables/Table4_sample_composition.tex)

.                 **** NEW VARIABLES (wrt table in the paper);
.         return list;

scalars:
            r(nmodels) =  6
              r(ccols) =  3

macros:
                 r(fn) : "..//tables/Table4_sample_composition.tex"
              r(names) : "aadt_10000_1 urban_2 sh_urb_10m_s_3 D_rig_4 sn_d_5 union_Mem_Total_6"
         r(m6_depname) : "Diri"
         r(m5_depname) : "Diri"
         r(m4_depname) : "Diri"
         r(m3_depname) : "Diri"
         r(m2_depname) : "Diri"
         r(m1_depname) : "Diri"
            r(cmdline) : "estout aadt_10000* urban* sh_urb_10m_s* D_rig* sn_d* union_Mem_Total* using `.."

matrices:
              r(coefs) :  6 x 18
              r(stats) :  1 x 6

.                         foreach comp_var of global appendix_var{;
  2.                                 gen comp_temp = `comp_var';
  3.                                 label var comp_temp "x";
  4.  //clear labels that cause formatting problems for estout ;20
>                                 eststo ,prefix(`comp_var'_): reghdfe    Diri  I2_t_exp_I2 c.I2_t_exp_I2#(
> `time') `time'
>                                                                                                          
> c.comp_temp c.comp_temp#c.I2_t_exp_I2 c.comp_temp#c.I2_t_exp_I2#(`time') 
>                                                                                                          
> ,  absor( id)  cluster(`cluster_var');
  5.                                 drop comp_temp;
  6.                                 estfe . `comp_var'_*, labels(id "Segment id FE");
  7.                                                         };
(2,905 missing values generated)
(dropped 4463 singleton observations)
(MWFE estimator converged in 1 iterations)

HDFE Linear regression                            Number of obs   =    178,687
Absorbing 1 HDFE group                            F(   6,    570) =      59.13
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.1202
                                                  Adj R-squared   =     0.0106
                                                  Within R-sq.    =     0.0680
Number of clusters (state_year) =        571      Root MSE        =    25.6567

                                               (Std. err. adjusted for 571 clusters in state_year)
--------------------------------------------------------------------------------------------------
                                 |               Robust
                            Diri | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
---------------------------------+----------------------------------------------------------------
                     I2_t_exp_I2 |  -945.0491   118.3731    -7.98   0.000     -1177.55   -712.5483
                                 |
            c.I2_t_exp_I2#c.time |   34.39918   8.950117     3.84   0.000     16.81994    51.97841
                                 |
                            time |   .0021973   .0784527     0.03   0.978    -.1518943     .156289
                       comp_temp |   -.339944   .5029626    -0.68   0.499     -1.32783    .6479423
                                 |
       c.comp_temp#c.I2_t_exp_I2 |  -34.91656   52.47644    -0.67   0.506    -137.9873    68.15423
                                 |
c.comp_temp#c.I2_t_exp_I2#c.time |  -2.601151   3.649072    -0.71   0.476    -9.768418    4.566117
                                 |
                           _cons |  -.0514942   1.274839    -0.04   0.968     -2.55545    2.452461
--------------------------------------------------------------------------------------------------

Absorbed degrees of freedom:
-----------------------------------------------------+
 Absorbed FE | Categories  - Redundant  = Num. Coefs |
-------------+---------------------------------------|
          id |     19791           0       19791     |
-----------------------------------------------------+
(average_grade_seg_7 stored)
(dropped 4819 singleton observations)
note: comp_temp is probably collinear with the fixed effects (all partialled-out values are close to zero; 
> tol = 1.0e-09)
(MWFE estimator converged in 1 iterations)
note: comp_temp omitted because of collinearity

HDFE Linear regression                            Number of obs   =    181,236
Absorbing 1 HDFE group                            F(   5,    572) =      57.16
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.1209
                                                  Adj R-squared   =     0.0105
                                                  Within R-sq.    =     0.0684
Number of clusters (state_year) =        573      Root MSE        =    25.6563

                                               (Std. err. adjusted for 573 clusters in state_year)
--------------------------------------------------------------------------------------------------
                                 |               Robust
                            Diri | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
---------------------------------+----------------------------------------------------------------
                     I2_t_exp_I2 |  -723.7661   142.6768    -5.07   0.000        -1004   -443.5318
                                 |
            c.I2_t_exp_I2#c.time |   16.52125   10.74698     1.54   0.125    -4.587108     37.6296
                                 |
                            time |  -.0033529   .0780418    -0.04   0.966    -.1566363    .1499306
                       comp_temp |          0  (omitted)
                                 |
       c.comp_temp#c.I2_t_exp_I2 |  -.8920995   .3508932    -2.54   0.011    -1.581296   -.2029032
                                 |
c.comp_temp#c.I2_t_exp_I2#c.time |    .045157   .0270484     1.67   0.096    -.0079692    .0982832
                                 |
                           _cons |  -.4091173   .9982539    -0.41   0.682    -2.369808    1.551573
--------------------------------------------------------------------------------------------------

Absorbed degrees of freedom:
-----------------------------------------------------+
 Absorbed FE | Categories  - Redundant  = Num. Coefs |
-------------+---------------------------------------|
          id |     20221           0       20221     |
-----------------------------------------------------+
(sh_elev_10m_s_8 stored)
(dropped 4819 singleton observations)
note: comp_temp is probably collinear with the fixed effects (all partialled-out values are close to zero; 
> tol = 1.0e-09)
(MWFE estimator converged in 1 iterations)
note: comp_temp omitted because of collinearity

HDFE Linear regression                            Number of obs   =    181,236
Absorbing 1 HDFE group                            F(   5,    572) =      65.91
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.1213
                                                  Adj R-squared   =     0.0109
                                                  Within R-sq.    =     0.0689
Number of clusters (state_year) =        573      Root MSE        =    25.6503

                                               (Std. err. adjusted for 573 clusters in state_year)
--------------------------------------------------------------------------------------------------
                                 |               Robust
                            Diri | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
---------------------------------+----------------------------------------------------------------
                     I2_t_exp_I2 |  -1125.557    141.008    -7.98   0.000    -1402.513   -848.6001
                                 |
            c.I2_t_exp_I2#c.time |   32.11025   9.344357     3.44   0.001     13.75681    50.46369
                                 |
                            time |   .0004458   .0777562     0.01   0.995    -.1522768    .1531683
                       comp_temp |          0  (omitted)
                                 |
       c.comp_temp#c.I2_t_exp_I2 |   2344.176   1166.375     2.01   0.045     53.27504    4635.076
                                 |
c.comp_temp#c.I2_t_exp_I2#c.time |  -55.65803   70.98332    -0.78   0.433    -195.0778    83.76172
                                 |
                           _cons |  -.4806607   .9944541    -0.48   0.629    -2.433888    1.472567
--------------------------------------------------------------------------------------------------

Absorbed degrees of freedom:
-----------------------------------------------------+
 Absorbed FE | Categories  - Redundant  = Num. Coefs |
-------------+---------------------------------------|
          id |     20221           0       20221     |
-----------------------------------------------------+
(sh_h20_10m_s_9 stored)

. return list;

macros:
        r(indicate_fe) : " "Segment id FE=0.id" "

.                                         log close;
      name:  <unnamed>
       log:  /Users/juanpablouribetrujillo/My Drive (jp.uribe86@gmail.com)/Research/MyPapers/MTU/JUE/analys
> is/sample_composition.log
  log type:  text
 closed on:  24 Jun 2024, 22:24:56
-----------------------------------------------------------------------------------------------------------
